﻿using System;
using System.Collections.Generic;
using System.Text;

namespace LP580.CG
{
    /// <summary>
    /// clsGiftProductPriceSpan 的摘要说明
    /// <summary>
    public class clsGiftProductPriceSpan
    {
        #region 构造函数

        public clsGiftProductPriceSpan() { }

        public clsGiftProductPriceSpan(int prmGiftProductPriceSpanID)
        {
            clsGiftProductPriceSpan entity = clsGiftProductPriceSpan.GetByKey(prmGiftProductPriceSpanID);
            this._giftproductpricespanid = entity._giftproductpricespanid;
            this._giftproductpricespanname = entity._giftproductpricespanname;
            this._giftproductpricespanorder = entity._giftproductpricespanorder;
        }

        #endregion

        public static clsGiftProductPriceSpan GetByKey(int prmGiftProductPriceSpanID)
        {
            clsGiftProductPriceSpan entity = new clsGiftProductPriceSpan();
            DBase dbo = new DBase();
            System.Data.IDataReader dr = dbo.ExecuteReader("SELECT * FROM [tbl_GiftProductPriceSpan] WHERE GiftProductPriceSpanID=" + prmGiftProductPriceSpanID.ToString());
            if (dr.Read())
            {
                entity._giftproductpricespanid = (int)dr["GiftProductPriceSpanID"];
                entity._giftproductpricespanname = (string)dr["GiftProductPriceSpanName"];
                entity._giftproductpricespanorder = (int)dr["GiftProductPriceSpanOrder"];
            }
            dr.Dispose();
            dr = null;
            dbo.CloseConn();
            dbo = null;
            return entity;
        }

        #region 增删改数据库操作

        public static int Insert(clsGiftProductPriceSpan prmEntity)
        {
            DataTableManage SaveDTM = new DataTableManage();
            string sql;
            sql = string.Format("insert into [tbl_GiftProductPriceSpan](" +
                            " [GiftProductPriceSpanName]," +
                            " [GiftProductPriceSpanOrder]" +
            ") values (" +
                    "@GiftProductPriceSpanName," +
                    "@GiftProductPriceSpanOrder" +
            ")");
            SaveDTM.Sql = sql;
            SaveDTM.AddNewParam("@GiftProductPriceSpanName", prmEntity._giftproductpricespanname);
            SaveDTM.AddNewParam("@GiftProductPriceSpanOrder", prmEntity._giftproductpricespanorder);
            SaveDTM.Insert();
            return 1;
        }

        public static bool Delete(int prmGiftProductPriceSpanID)
        {
            DBase dbo = new DBase();
            dbo.ExecSql("DELETE FROM [tbl_GiftProductPriceSpan] WHERE GiftProductPriceSpanID=" + prmGiftProductPriceSpanID.ToString());
            dbo.CloseConn();
            dbo = null;
            return true;
        }

        public static bool Update(clsGiftProductPriceSpan prmEntity)
        {
            DataTableManage SaveDTM = new DataTableManage();
            string sql;
            sql = "UPDATE [tbl_GiftProductPriceSpan] SET " +
                "[GiftProductPriceSpanName] = @GiftProductPriceSpanName, " +
                "[GiftProductPriceSpanOrder] = @GiftProductPriceSpanOrder " +
            " WHERE GiftProductPriceSpanID=@GiftProductPriceSpanID";
            SaveDTM.Sql = sql;
            SaveDTM.AddNewParam("@GiftProductPriceSpanName", prmEntity._giftproductpricespanname);
            SaveDTM.AddNewParam("@GiftProductPriceSpanOrder", prmEntity._giftproductpricespanorder);
            SaveDTM.AddNewParam("@GiftProductPriceSpanID", prmEntity._giftproductpricespanid);
            SaveDTM.Update();
            return true;
        }

        #endregion

        public static List<clsGiftProductPriceSpan> GetCollection()
        {
            List<clsGiftProductPriceSpan> ls = new List<clsGiftProductPriceSpan>();
            DBase dbo = new DBase();
            string sql = "SELECT GiftProductPriceSpanID FROM [tbl_GiftProductPriceSpan] ORDER BY GiftProductPriceSpanID DESC";
            System.Data.IDataReader dr = dbo.ExecuteReader(sql);
            while (dr.Read())
            {
                ls.Add(clsGiftProductPriceSpan.GetByKey((int)dr[0]));
            }
            dr.Dispose();
            dr = null;
            dbo.CloseConn();
            dbo = null;
            return ls;
        }
        public static string GetName(int id)
        {
            DBase db = new DBase();
            string name = db.ExecuteScalar("select GiftProductPriceSpanName from tbl_GiftProductPriceSpan where GiftProductPriceSpanID=" + id.ToString()).ToString();
            db = null;
            return name;
        }
        #region 字段属性

        private int _giftproductpricespanid = 0;
        /// <summary>
        /// 礼品价格区间ID-自增
        /// </summary>
        public int GiftProductPriceSpanID
        {
            get { return _giftproductpricespanid; }
            set { _giftproductpricespanid = value; }
        }

        private string _giftproductpricespanname = "";
        /// <summary>
        /// 价格区间名称
        /// </summary>
        public string GiftProductPriceSpanName
        {
            get { return _giftproductpricespanname; }
            set { _giftproductpricespanname = value; }
        }

        private int _giftproductpricespanorder = 0;
        /// <summary>
        /// 排序值勤
        /// </summary>
        public int GiftProductPriceSpanOrder
        {
            get { return _giftproductpricespanorder; }
            set { _giftproductpricespanorder = value; }
        }

        #endregion
    }
}
